<?php
require 'model-db-connection/config.php';
$config = require 'model-db-connection/qrc_conf.properties.php';
$projectCode = $_GET['project_code'];

$sqlSelectProjectName = "SELECT project_name from QRC_PROJECT where project_code='$projectCode'";
$result = mysql_query($sqlSelectProjectName);
if ($row = mysql_fetch_assoc($result)) {
    $strProjectName = $row['project_name'];
}
?>
<script src="assets/components/common/tables/responsive/assets/lib/js/footable.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/tables/responsive/assets/custom/js/tables-responsive-footable.init.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/modules/admin/notifications/gritter/assets/lib/js/jquery.gritter.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/modules/admin/modals/assets/js/bootbox.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/editors/wysihtml5/assets/lib/js/wysihtml5-0.3.0_rc2.min.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/editors/wysihtml5/assets/lib/js/bootstrap-wysihtml5-0.0.2.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/editors/wysihtml5/assets/custom/wysihtml5.init.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/wizards/assets/lib/jquery.bootstrap.wizard.js?v=v1.0.2&sv=v0.0.1"></script>
<script src="assets/components/common/forms/wizards/assets/custom/js/form-wizards.init.js"></script>
<!--<script src="js/jquery.form.js"></script>-->
<div class="widget">
    <div class="widget-head">
        <h4 class="heading">Work Order (โครงการ <?= $strProjectName ?>)</h4>
        <a href="#" data-toggle="modal" class="btn btn-xs btn-inverse pull-right" id="close_project_btn" style="margin-top: 6px;"><i class="fa fa-minus-circle fa-fw"></i> Close</a>
        <a href="#modal-project-order" data-toggle="modal" class="btn btn-xs btn-inverse pull-right" id="new_project_order_btn" style="margin-top: 6px; margin-right: 5px;"><i class="fa fa-plus-circle fa-fw"></i> New Order</a>

        <div class="clearfix"></div>
    </div>
    <div class="widget-body innerAll inner-2x">
        <!-- Table -->
        <table class="footable table table-striped table-primary">

            <!-- Table heading -->
            <thead>
                <tr>
                    <th data-class="expand" class="center">Project Code</th>
                    <th data-hide="phone,tablet">Document No.</th>
                    <th data-hide="phone,tablet">PO No.</th>
                    <th data-hide="phone,tablet">PO Owner</th>
                    <th data-hide="phone,tablet">PO Sender</th>
                    <th data-hide="phone,tablet">Date</th>
                    <th data-hide="phone,tablet">Order Type</th>
                    <th data-hide="phone,tablet">Remark</th>
                    <th data-hide="phone,tablet">PO Image</th>                    
                    <th class="center">Project Status</th>
                    <th class="center">Plan</th>
                    <th class="center">Plot</th>
                    <th class="center">Plan Size</th>
                    <th class="center">Unit Price</th>
                    <th class="center">Amount</th>
                    <th class="center">Included VAT 7%</th>
                    <th class="center"></th>
                </tr>
            </thead>
            <!-- // Table heading END -->

            <!-- Table body -->
            <tbody>
                <?php
                $sqlSelectAllProjectRecord = "SELECT qpo.project_code as project_code,
                        qpo.project_order_id as order_id,
			qpo.project_order_plan as project_plan,
			qpo.project_order_plot as project_plot,
			qpo.document_no as document_no,
			qpo.po_no as po_no,
			qpo.po_owner as po_owner,
			qpo.po_sender as po_sender,
			qpo.created_date_time as created_date_time,
			qpot.service_name as order_type,
			qpo.plan_size as plan_size,
			qpo.unit_price as unit_price,
			qpo.amount as amount,
			qpo.include_vat as vat,
			qpo.image_name as imgName,
                        qpo.project_status as project_status,
                        qpo.remark as project_order_remark
                        FROM QRC_PROJECT_ORDER qpo
                        LEFT JOIN QRC_TYPE_OF_SERVICE qpot ON qpo.order_type = qpot.service_id
                        WHERE qpo.project_code like '$projectCode'
                        ORDER BY qpo.created_date_time DESC;";
                $sqlGetAllData = mysql_query($sqlSelectAllProjectRecord);
                if (mysql_num_rows($sqlGetAllData) >= 1) {
                    while ($row = mysql_fetch_assoc($sqlGetAllData)) {

                        echo '<tr class = "gradeX">';
                        echo '<td>' . $row['project_code'] . '</td>';
                        echo '<td>' . $row['document_no'] . '</td>';
                        echo '<td>' . $row['po_no'] . '</td>';
                        echo '<td>' . $row['po_owner'] . '</td>';
                        echo '<td>' . $row['po_sender'] . '</td>';
                        echo '<td>' . $row['created_date_time'] . '</td>';
                        echo '<td>' . $row['order_type'] . '</td>';
                        echo '<td>' . $row['project_order_remark'] . '</td>';

                        $selectImageFromQRCPOIMG = "SELECT IMAGE_PATH AS IMAGE_PATH FROM QRC_PO_IMAGE WHERE TEMP_PO_ID LIKE '" . $row['imgName'] . "'";
                        $sqlGetAllDatas = mysql_query($selectImageFromQRCPOIMG);
                        while ($rop = mysql_fetch_assoc($sqlGetAllDatas)) {
                            echo '<td><d class="fancybox-effects-d" href="image/uploads/' . $rop['IMAGE_PATH'] . '" title="' . $rop['IMAGE_PATH'] . '" onlick="changeAttrHref()"><img src="image/uploads/' . $rop['IMAGE_PATH'] . '" alt="Smiley face" width="200"></d></td>';
                        }
                        if ($row['project_status'] == "New") {
                            echo '<td class = "center" style="color: blue;">' . $row['project_status'] . '</td>';
                        } else if ($row['project_status'] == "Complete") {
                            echo '<td class = "center" style="color: green;">' . $row['project_status'] . '</td>';
                        } else if ($row['project_status'] == "Assign") {
                            echo '<td class = "center" style="color: orange;">' . $row['project_status'] . '</td>';
                        } else {
                            echo '<td class = "center">' . $row['project_status'] . '</td>';
                        }
                        echo '<td class = "center">' . $row['project_plan'] . '</td>';
                        echo '<td class = "center">' . $row['project_plot'] . '</td>';
                        echo '<td class = "center">' . $row['plan_size'] . '</td>';
                        echo '<td class = "center">' . $row['unit_price'] . '</td>';
                        echo '<td class = "center">' . $row['amount'] . '</td>';
                        echo '<td class = "center">' . $row['vat'] . '</td>';
                        echo '<td class = "center">';
                        echo '<a href = "#modal-project-order" data-toggle = "modal" class = "btn btn-primary" onclick=editPO("' . $row['project_code'] . '","' . $row['order_id'] . '")><i class = "icon-document-line"></i> Edit</a>';
                        echo '<button class = "btn btn-danger" style="margin-left: 5px" onclick=deletePO("' . $row['order_id'] . '","' . $row['project_code'] . '","' . $row['imgName'] . '")><i class = "fa fa-trash-o"></i> Delete</button>';

                        echo '</td>';
                        echo '</tr>';
                    }
                } else {
                    echo '<tr class = "gradeX">';
                    echo '<td colspan="7" align="center">No Record Found</td>';
                    echo '</tr>';
                }
                ?>
            </tbody>
            <!-- // Table body END -->

        </table>
        <!-- // Table END -->

    </div>
</div>
<div style="display: none;">
    <div id="inline1" style="width:400px;height:100px;overflow:auto;">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque. Nulla sit amet sem sapien. Vestibulum imperdiet porta ante ac ornare. Nulla et lorem eu nibh adipiscing ultricies nec at lacus. Cras laoreet ultricies sem, at blandit mi eleifend aliquam. Nunc enim ipsum, vehicula non pretium varius, cursus ac tortor. Vivamus fringilla congue laoreet. Quisque ultrices sodales orci, quis rhoncus justo auctor in. Phasellus dui eros, bibendum eu feugiat ornare, faucibus eu mi. Nunc aliquet tempus sem, id aliquam diam varius ac. Maecenas nisl nunc, molestie vitae eleifend vel, iaculis sed magna. Aenean tempus lacus vitae orci posuere porttitor eget non felis. Donec lectus elit, aliquam nec eleifend sit amet, vestibulum sed nunc.
    </div>
</div>
<div class="modal fade" id="modal-project-order">

    <div class="modal-dialog">
        <div class="modal-content">

            <!-- Modal heading -->
            <div class="modal-header">
                <button type="button" class="close close_project_order" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h2 class="modal-title">Project Order Create/Edit</h2>
            </div>
            <!-- // Modal heading END -->

            <!-- Modal body -->
            <div class="modal-body">
                <div class="innerAll">
                    <div class="innerLR">
                        <div id="rootwizard" class="wizard">

                            <!-- Wizard heading -->
                            <div class="wizard-head">
                                <ul>
                                    <li><a href="#tab1" data-toggle="tab"><img src="image/keyboard37.png" width="45px" height="45px"/></a></li>
                                    <li><a href="#tab2" data-toggle="tab"><img src="image/keyboard31.png" width="45px" height="45px"/></a></li>
                                    <!--<li><a href="#tab3" data-toggle="tab"><img src="image/number22.png" width="45px" height="45px"/></a></li>-->
                                </ul>
                            </div>
                            <!-- // Wizard heading END -->

                            <div class="widget">

                                <!-- Wizard Progress bar -->
                                <div class="widget-head progress progress-primary" id="bar">
                                    <div class="progress-bar">Step <strong class="step-current">1</strong> of <strong class="steps-total">3</strong> - <strong class="steps-percent">100%</strong></div>
                                </div>
                                <!-- // Wizard Progress bar END -->

                                <div class="widget-body">
                                    <div class="tab-content">
                                        <!-- Step 1 -->
                                        <div class="tab-pane active" id="tab1">
                                            <div class="row">

                                                <div class="col-md-12">
                                                    <label for="project_code">Project Code (หมายเลขโครงการ)</label>
                                                    <input type="text" id="project_code_orderPage" name="project_code" class="col-md-6 form-control" value="<?= $projectCode ?>" disabled="true" />
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_order_status">Status (สถานะ)</label>
                                                    <select class="form-control" id="project_order_status" name="project_order_status">
                                                        <option value="New">New</option>
                                                        <option value="Assign">Assign</option>
                                                        <option value="Pending">Pending</option>
                                                        <option value="Cancel">Cancel</option>
                                                        <option value="Complete">Complete</option>
                                                        <option value="Close">Close</option>
                                                    </select>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_po_no">PO No. (เลขที่ใบสั่งจ้าง)</label>
<!--                                                    <input type="text" id="project_po_no" name="project_po_no" class="col-md-6 form-control"/>-->
                                                    <select class="form-control" id="po_no_no" name="po_no_no">
                                                        <option value="0"></option>
                                                        <?php
                                                        $sqlSelectProjectType = "SELECT * FROM qrc_po;";
                                                        $resultSet = mysql_query($sqlSelectProjectType);
                                                        while ($row = mysql_fetch_array($resultSet)) {
                                                            echo '<option value="' . $row['PO_ID'] . '">' . $row['PO_PO_NO'] . '</option>';
                                                        }
                                                        ?>      
                                                    </select>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_document_no">Document No. (เลขที่)</label>
                                                    <input type="text" id="project_document_no" name="project_document_no" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_plan">Plan (แบบบ้าน)*</label>
                                                    <select class="form-control" id="project_plan" name="project_plan" disabled="true">
                                                        <option value="0">---Please select---</option>
                                                        <option value="LN01">LN01</option>
                                                        <option value="LN02">LN02</option>
                                                        <option value="AT021">AT021</option>
                                                    </select>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_plot">Plot (แปลงบ้าน)*</label>
                                                    <select class="form-control" id="project_plot" name="project_plot" disabled="true">
                                                        <option value="0">---Please select---</option>
                                                        <option value="A02">A02</option>
                                                        <option value="A03">A03</option>
                                                        <option value="89">89</option>
                                                        <option value="90">90</option>
                                                    </select>
                                                    <div class="separator"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- // Step 1 END -->

                                        <!-- Step 2 -->
                                        <div class="tab-pane" id="tab2">
                                            <div class="row">

                                                <div class="col-md-12">
                                                    <label for="project_po_owner">PO Owner. (เจ้าของ PO)</label>
                                                    <input type="text" id="project_po_owner" name="project_po_owner" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_po_sender">PO Sender. (จนท. PO)</label>
                                                    <input type="text" id="project_po_sender" name="project_po_sender" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_issue_date">Issue Date (วันที่)</label>
                                                    <input type="text" id="project_issue_date" name="project_issue_date" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_order_type">Order Type (ประเภทงาน)</label>
                                                    <select class="form-control" id="project_order_type" name="project_order_type" disabled="true">
                                                        <option value="0">---Please select---</option>
                                                        <?php
                                                        $sqlSelectProjectType = "SELECT * FROM QRC_TYPE_OF_SERVICE;";
                                                        $resultSet = mysql_query($sqlSelectProjectType);
                                                        while ($row = mysql_fetch_array($resultSet)) {
                                                            echo '<option value="' . $row['service_id'] . '">' . $row['service_name'] . '</option>';
                                                        }
                                                        ?>      
                                                    </select>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_plan_size">Plan Size (ขนาด ตร.ม.)</label>
                                                    <input type="text" id="project_plan_size" name="project_plan_size" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_unit_price">Unit Price (ราคาต่อหน่วย)</label>
                                                    <input type="text" id="project_unit_price" name="project_unit_price" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_amount">Amount (ราคารวม)</label>
                                                    <input type="text" id="project_amount" name="project_amount" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12">
                                                    <label for="project_vat">Grand Total included VAT 7%</label>
                                                    <input type="text" id="project_vat" name="project_vat" class="col-md-6 form-control" disabled="true"/>
                                                    <div class="separator"></div>
                                                </div>
                                                <div class="col-md-12" id="shown_remark">
                                                    <label for="project_order_remark">Remark</label>
                                                    <textarea rows="4" cols="30" class="col-md-6 form-control" id="project_order_remark" name="project_order_remark"></textarea>
                                                    <div class="separator"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <!-- // Step 2 END -->
                                        <div id="tab3">
                                            <fieldset>
                                                <legend>Assign Detail</legend>
                                                <form id="assign_detail_in_order_page">
                                                    <div class="col-md-12">
                                                        <label for="project_plan_size">Project Manager (ผู้จัดการโครงการ)</label>
                                                        <input type="text" id="wo_project_managers" name="project_plan_size" class="col-md-6 form-control" disabled="true"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <label for="project_unit_price">Project Foreman (ผู้ควบคุมงานของโครงการ)</label>
                                                        <input type="text" id="wo_project_foreman" name="wo_project_foreman" class="col-md-6 form-control" disabled="true"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <label for="project_amount">Supervisor Control (ผู้ควบคุมงานของลูกค้า)</label>
                                                        <input type="text" id="wo_supervisor_control" name="wo_supervisor_control" class="col-md-6 form-control" disabled="true"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12" id="team_code_error">
                                                        <label for="project_vat">Team Code (หมายเลขทีมช่าง) *</label>
                                                        <!--<input type="text" id="wo_team_code" name="wo_team_code" class="col-md-6 form-control"/>-->
                                                        <select class="form-control" id="wo_team_code" name="wo_team_code">
                                                            <option value="0"></option>
                                                            <?php
                                                            $sqlSelectProjectType = "SELECT * FROM QRC_TEAM_BUILDER;";
                                                            $resultSet = mysql_query($sqlSelectProjectType);
                                                            while ($row = mysql_fetch_array($resultSet)) {
                                                                echo '<option value="' . $row['tCode'] . '">' . $row['tCode'] . '</option>';
                                                            }
                                                            ?>      
                                                        </select>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <label for="project_vat">Team Name (ชื่อทีม) *</label>
                                                        <input type="text" id="wo_team_name" name="wo_team_name" class="col-md-6 form-control" disabled="true"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <label for="project_vat">Assign Date (วันที่)</label>
                                                        <input type="text" id="wo_assign_date" name="wo_assign_date" class="col-md-6 form-control" disabled="true"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <label for="project_vat">Target Date (วันที่)</label>
                                                        <input type="text" id="wo_target_date" name="wo_target_date" class="col-md-6 form-control" placeholder="dd-mm-yyyy"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <label for="project_vat">Remark</label>
                                                        <input type="text" id="wo_remark" name="wo_remark" class="col-md-6 form-control"/>
                                                        <div class="separator"></div>
                                                    </div>
                                                </form>
                                            </fieldset>
                                        </div>
                                        <!-- // Step 3 END -->

                                    </div>

                                    <!-- Wizard pagination controls -->
                                    <ul class="pagination margin-bottom-none">
                                        <li class="primary previous first"><a href="#" class="no-ajaxify">First</a></li>
                                        <li class="primary previous"><a href="#" class="no-ajaxify">Previous</a></li>
                                        <li class="last primary"><a href="#" class="no-ajaxify">Last</a></li>
                                        <li class="next primary"><a href="#" class="no-ajaxify">Next</a></li>
                                        <li class="next finish primary" style="display:none;"><a href="#" class="no-ajaxify">Finish</a></li>
                                        <li class="primary first"><a href="#" class="close_project_order">Close</a></li>
                                    </ul>
                                    <!-- // Wizard pagination controls END -->

                                </div>
                            </div>
                        </div>
                        <!-- // Form Wizard / Arrow navigation & Progress bar END -->


                    </div>
                </div>
            </div>
        </div>

        <!-- // Modal body END -->

    </div>
</div>
<input type="hidden" id="project_oid" value=""/>
<input type="hidden" id="project_po_no_name" value=""/>
<input type="hidden" id="project_po_no_id" value=""/>
<script type="text/javascript">
    var initialState = "SaveState";
    $(document).ready(function() {
        var d = new Date();
        var curr_date = d.getDate();
        var curr_month = d.getMonth();
        var curr_year = d.getFullYear();
        $("#wo_assign_date").val(curr_date + "-" + curr_month + "-" + curr_year);
        $("#wo_team_code").change(function() {
            var tCode = $("#wo_team_code").val();
            var jqxhr = $.post("model/GetAllTeamForEdit.php?teamID=" + tCode);
            jqxhr.success(function(data) {
                $.unblockUI();
                obj = JSON.parse(data);
                $("#wo_team_name").val(obj.t_Name);
            });
            jqxhr.error(function(data) {
                window.location.replace("error.php?error_msg=" + data);
            });
        });
        $(".close_project_order").click(function() {
            var project_code = $("#project_code_orderPage").val();
            $("#modal-project-order").modal('hide');
            setTimeout(function()
            {
                $("#load_project_order").load("ProjectOrderPage.php?project_code=" + project_code);
            }
            , 500);

        });
        $("#wo_target_date").datepicker();
        $("#tab3").hide();
        $("#project_order_status").change(function() {

            if ($("#project_order_status").val() === "Assign") {
                blockPage();
                var project_code = $("#project_code_orderPage").val();
                var jqxhr = $.post("model/GetAllProjectForEdit.php?project_code=" + project_code);
                jqxhr.success(function(data) {
                    $.unblockUI();
                    obj = JSON.parse(data);
                    $("#wo_project_managers").val(obj.project_manager);
                    $("#wo_project_foreman").val(obj.project_foreman);
                    $("#wo_supervisor_control").val(obj.supervisor_control);
                    setTimeout(function()
                    {
                        $("#tab3").show();
                    }
                    , 500);
                });
                jqxhr.error(function(data) {
                    window.location.replace("error.php?error_msg=" + data);
                });
            } else {
                $("#tab3").hide();
            }
        });
        $("#po_no_no").change(function() {
            var po_id = $("#po_no_no").val();
            var jqxhr = $.post("model/GetWorkOrderByPOID.php?po_id=" + po_id);
            jqxhr.success(function(data) {
                obj = JSON.parse(data);
//                alert(data);
                $("#project_plan").val(obj.PO_HOME_PLAN);
                $("#project_plot").val(obj.PO_HOME_PLOT);
                $("#project_document_no").val(obj.PO_DOCUMENT_NO);
                $("#project_po_owner").val(obj.PO_OWNER);
                $("#project_po_sender").val(obj.PO_SENDER);
                $("#project_order_type").val(obj.order_type_name);
                $("#project_plan_size").val(obj.PO_PLAN_SIZE);
                $("#project_unit_price").val(obj.PO_UNIT_PRICE);
                $("#project_amount").val(obj.PO_AMOUNT);
                $("#project_vat").val(obj.PO_VAT);
                $("#project_po_no_name").val(obj.PO_PO_NO);
                $("#project_po_no_id").val(obj.po_id);
                $.unblockUI();
            });
            jqxhr.error(function(data) {
                window.location.replace("error.php?error_msg=" + data);
            });
        });
        $("#close_project_btn").click(function() {
            $(".about_project").show();
            $("#load_project_order").empty();
            $("#link_to_project_order").empty();
        });
        $("#new_project_order_btn").click(function() {
            initialState = "SaveState";
            var m_names = new Array("มกราคม", "กุมภาพันธ์", "มีนาคม",
                    "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน",
                    "ตุลาคม", "พฤศจิกายน", "ธันวาคม");
            var d = new Date();
            var curr_date = d.getDate();
            var curr_month = d.getMonth();
            var curr_year = d.getFullYear();
            $("#project_issue_date").val(curr_date + " " + m_names[curr_month]
                    + " " + (curr_year + 543));
            $("a[data-toggle*='tab']:first").trigger('click');
            $("#shown_remark").hide();
            $("#project_document_no").val("");
            $("#project_order_status").val("New");
            $("#project_plan").val("0");
            $("#project_plot").val("0");
            $("#project_po_no").val("");
            $("#project_po_owner").val("");
            $("#project_po_sender").val("");
            $("#project_order_type").val("0");
            $("#project_plan_size").val("");
            $("#project_unit_price").val("");
            $("#project_amount").val("");
            $("#project_vat").val("");
            $("#preview").html("");
        });
    });
    function deletePO(POID, project_code, imagePath) {
        var jqxhr = $.post("model/DeleteProjectOrder.php?project_order_code=" + POID + "&imagePath=" + imagePath);
        jqxhr.success(function(data) {
            if (data == 1) {
                setTimeout(function()
                {
                    $("#load_project_order").load("ProjectOrderPage.php?project_code=" + project_code);
                    $.gritter.add({
                        title: 'Success!',
                        text: "<?= $config['msg_delete_success'] ?>"
                    });
                }
                , 500);
            } else {
                alert("ไม่สามารถลบข้อมูลได้");
            }
        });
        jqxhr.error(function(data) {
            window.location.replace("error.php?error_msg=" + data);
        });
    }
    function editPO(project_code, project_order_id) {
        initialState = "EditState";
        $("#project_oid").val(project_order_id);
        $("#shown_remark").show();
        var jqxhr = $.post("model/GetAllProjectOrderForEdit.php?project_code=" + project_code + "&order_id=" + project_order_id);
        jqxhr.success(function(data) {

            obj = JSON.parse(data);
//            alert(obj.imgName);
            $("#project_document_no").val(obj.document_no);
            $("#project_order_status").val(obj.project_status);
            $("#project_plan").val(obj.project_plan);
            $("#project_plot").val(obj.project_plot);
            $("#po_no_no").val(obj.imgName);
            $("#project_po_owner").val(obj.po_owner);
            $("#project_po_sender").val(obj.po_sender);
            $("#project_issue_date").val(obj.created_date_time);
            $("#project_order_type").val(obj.order_type);
            $("#project_plan_size").val(obj.plan_size);
            $("#project_unit_price").val(obj.unit_price);
            $("#project_amount").val(obj.amount);
            $("#project_vat").val(obj.vat);
            $("#project_order_remark").val(obj.project_order_remark);
            $("a[data-toggle*='tab']:first").trigger('click');
            $("#project_po_no_name").val(obj.po_no);
            if (obj.project_status == "Assign") {
                $("#tab3").show();
            }
        });
        jqxhr.error(function(data) {
            window.location.replace("error.php?error_msg=" + data);
        });
    }
    function blockPage() {
        $.blockUI({message: 'Operation in progress...', css: {
                border: 'none',
                padding: '15px',
                backgroundColor: '#000',
                '-webkit-border-radius': '10px',
                '-moz-border-radius': '10px',
                opacity: .5,
                color: '#fff'
            }});
    }
</script>
<style>
    .preview
    {
        width:200px;
        border:solid 1px #dedede;
        padding:10px;
    }
    #preview
    {
        color:#cc0000;
        font-size:12px
    }

</style>